<?php

namespace App\Http\Controllers\Admin;


use App\Http\Controllers\Controller;
use Illuminate\Support\Facades\DB;
use Illuminate\Http\Request;
use Illuminate\Support\Facades\Storage;

class ExhibitionController extends Controller
{
    //

    public function getExhibition(){
        try{
            $results = DB::table('aboutcompany')->where('type','=','6')->where('aboutcompany_id','=','12')->get();
            //dd($results);

           return view('Admin.exhibition',['result'=> $results]);

        }catch (Exception $e){

            $info =  $e->getMessage().'failed line:'.$e->getLine().'failed string:'.$e->getTraceAsString();
            return json_encode(['msg'=>0,'data' => $info]);
            exit;
        }
    }
    public function wechatImgupload(Request $request){

        if($request->isMethod('POST')){
            $file = $request->file('aboutcompany_image');;

            if($file->isValid()){

                $mimetype = $file->getClientMimeType();
                $originalName = $file->getClientOriginalName();

                $ext = $file->getClientOriginalExtension();
                $realPath = $file->getRealPath();

                $filename = date('Y-m-d-H-i-s') . '-' . uniqid() . '.' . $ext;

                $bool = Storage::disk('uploads')->put($filename,file_get_contents($realPath));



                $path = "/../public/uploads/";
                $url = '/uploads/'.$filename;

                $result = DB::table('aboutcompany')->where('aboutcompany_id','=','12')->update([
                    'aboutcompany_image'=> $url,
                ]);
                if($result){
                    return redirect('/admin/getExhibition');
                }
            }
            exit;
        }
    }


    public function changeInfo(Request $request){

        try{

            $title= $request->input('title');
            $other= $request->input('other');
            $results = DB::table('aboutcompany')->where('aboutcompany_id','=','12')->update(['title'=>$title,'other'=>$other]);

            if($results){
                return redirect('/admin/getExhibition');
            }

        }catch (Exception $e){

            $info =  $e->getMessage().'failed line:'.$e->getLine().'failed string:'.$e->getTraceAsString();
            return json_encode(['msg'=>0,'data' => $info]);
            exit;
        }
    }

}
